﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Webcam.Image
{
    /// <summary>A point</summary>
    public struct Point
    {
        int _x;
        int _y;

        /// <summary>
        /// The X coordinate
        /// </summary>
        public int X
        {
            get { return _x; }
            set { _x = value; }
        }

        /// <summary>
        /// The Y coordinate
        /// </summary>
        public int Y
        {
            get { return _y; }
            set { _y = value; }
        }


        /// <summary>
        /// Create a point with X and Y coordinates
        /// </summary>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        public Point(int X, int Y)
        {
            this._x = X;
            this._y = Y;
        }

        /// <summary>
        /// Create a point with the same x and y value
        /// </summary>
        /// <param name="p"></param>
        public Point(int p)
        {
            _x = p;
            _y = p;
        }

        /// <summary>
        /// An empty point
        /// </summary>
        public static Point Empty = new Point(0, 0);

        /// <summary>
        /// Subtract p2 from p1. ie p1-p2
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public static Point Subtract(Point p1, Point p2)
        {
            return new Point(p1.X - p2.X, p1.Y - p2.Y);
        }

        /// <summary>Perform p1+p2</summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public static Point Add(Point p1, Point p2)
        {
            return new Point(p1.X + p2.X, p1.Y + p2.Y);
        }

        /// <summary>
        /// Get the midpoint between two points
        /// </summary>
        /// <param name="p"></param>
        /// <param name="pp"></param>
        /// <returns></returns>
        public static Point MidPoint(Point p, Point pp)
        {
            int x = p.X + pp.X;
            int y = p.Y + pp.Y;

            return new Point(x / 2, y / 2);
        }

    }
}
